<?php
//https://developer.aliyun.com/composer
//https://guzzle-cn.readthedocs.io/zh_CN/latest/quickstart.html
//https://packagist.org/packages/guzzlehttp/guzzle#6.5.5
// composer require guzzlehttp/guzzle:~6.0
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
// Create a client with a base URI
/*
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/guzzle/']);
$response = $client->request('POST','server.php',[
    'form_params'=>[
        'time'=>time(),
        'hobby'=>[
            'football',
            'basketball',
        ]
    ],
]);
echo $response->getBody();
*/
/*
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/guzzle/']);
$response = $client->request('POST','server.php',[
    'multipart' => [
        [
            'name'     => 'time',
            'contents' => time(),
        ],
        [
            'name'     => '038.jpg',
            'contents' => fopen('038.jpg', 'r')
        ],
        
    ]
]);
echo $response->getBody();
*/
/*
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/guzzle/']);
$response = $client->request('POST','json.php',[
    'json' => ['foo' => 'bar']
]);
echo $response->getBody();
*/
/*
try {
    $client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/guzzle/']);
    $response = $client->request('POST','body.php',[
        'body'=>fopen('038.jpg','r'),
    ]);
    echo $response->getBody();
}catch(RequestException $e){
    var_dump($e);
}
*/

try{
    $client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/guzzle/']);
    $response = $client->request('POST','none.php',[
        'form_params'=>[
            'time'=>time(),
        ],
    ]);
    echo $response->getBody();
    echo $response->getStatusCode();
}catch(RequestException $e){
    echo htmlentities($e->getMessage());
}
